package com.fotile.weixin.event.dto;

import com.fotile.weixin.event.param.ArticleItem;
import lombok.Data;

import javax.validation.constraints.Null;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlElements;
import java.util.List;

@Data
public class ResponseDTO {
//    企业微信CorpID
    @XmlElement(name = "ToUserName")
    private String toUserName;
//    成员UserID
    @XmlElement(name = "FromUserName")
    private String platformUserName;
//    消息创建时间（整型）
    @XmlElement(name = "CreateTime")
    private String createTime;
//    消息类型，此时固定为：event
    @XmlElement(name = "MsgType")
    private String msgType;
    @XmlElement(name = "Content",required=false)
    private String content;
    @XmlElement(name = "FuncFlag",required=false)
    private Integer funcFlag;
    @XmlElement(name = "ArticleCount",required=false)
    private Integer articleCount;
    @XmlElementWrapper(name="Articles")@XmlElements(@XmlElement(name="item",required=false))
    private List<ArticleItem> items;
    //企业号应用ID
    @XmlElement(name = "AgentID")
    private String agentID;

    private Integer id;
    public void setItems(List<ArticleItem> items) {
        this.items = items;
        this.setArticleCount(items.size());
        this.setFuncFlag(1);
        this.setMsgType("news");
    }
    public ResponseDTO(String toUserName,String platformUserName,String createTime,String agentId){
        this.toUserName=toUserName;
        this.platformUserName=platformUserName;
        this.createTime=createTime;
        this.agentID=agentId;
    }

    public ResponseDTO(RequestDTO request){
        this(request.getPlatformUserName(), request.getToUserName(), request.getCreateTime(),request.getAgentID());
    }
}
